//logs.js
Component({
    properties: {

    },
  data: {
  },
    methods: {
      canvasToBase: function (url) {
          const  width = 100;
          const  height = 100
          const ctx = wx.createCanvasContext('canvasToBase')
          console.log(url)
          ctx.drawImage(url, 0, 0,width, height)
          ctx.draw(false, function () {
              console.log(11111)
              wx.canvasGetImageData({
                  canvasId: 'canvasToBase',
                  x: 0,
                  y: 0,
                  width: width,
                  height: height,
                  success(resData) {
                      console.log(resData)
                      // 3. png编码
                      let pngData = upng.encode([resData.data.buffer], resData.width, resData.height)
                      // 4. base64编码
                      let base64 = wx.arrayBufferToBase64(pngData)
                      console.log(base64)
                  }
              })
          })
      }
  }
})
